home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / hp95 / freyja_t.z / freyja_t / white.c < prev    next >
C/C++ Source or Header  |  1992-04-14  |  7KB  |  371 lines

  1. /* WHITE.C -- Whitespace-Oriented Commands
  2.  
  3.     Written July 1991 by Craig A. Finseth
  4.     Copyright 1991 by Craig A. Finseth
  5. */
  6.  
  7. #include "freyja.h"
  8.  
  9.  
  10. /* ------------------------------------------------------------ */
  11.  
  12. /* Delete the surounding whitespace. */
  13.  
  14. void
  15. WDelFWhite()
  16.     {
  17.     BMarkToPoint(cwin->point);
  18.     MovePastF(IsWhite);
  19.     BRegDelete(cwin->point);
  20.     }
  21.  
  22.  
  23. /* ------------------------------------------------------------ */
  24.  
  25. /* Delete the spaces and tabs around the point. */
  26.  
  27. void
  28. WDelWhite()
  29.     {
  30.     MovePastB(IsWhite);
  31.     BMarkToPoint(cwin->point);
  32.     MovePastF(IsWhite);
  33.     BRegDelete(cwin->point);
  34.     }
  35.  
  36.  
  37. /* ------------------------------------------------------------ */
  38.  
  39. /* Perform consistency and reasonableness checking on the conf_buffer
  40. data. */
  41.  
  42. void
  43. WFixup(cptr)
  44.     struct conf_buffer *cptr;
  45.     {
  46.     if (cptr->left_margin < 0) cptr->left_margin = 0;
  47.     if (cptr->left_margin > 100) cptr->left_margin = 100;
  48.  
  49.     if (cptr->right_margin <= 0) cptr->right_margin = 9999;
  50.     if (cptr->right_margin <= cptr->left_margin + 2)
  51.         cptr->right_margin = cptr->left_margin + 3;
  52.     if (cptr->right_margin > 9999) cptr->right_margin = 9999;
  53.  
  54.     if (cptr->tab_spacing < 1) cptr->tab_spacing = 1;
  55.     if (cptr->tab_spacing > 50) cptr->tab_spacing = 50;
  56.  
  57.     if (cptr->fill != 'N' && cptr->fill != 'F' && cptr->fill != 'W')
  58.         cptr->fill = 'N';
  59.     }
  60.  
  61.  
  62. /* ------------------------------------------------------------ */
  63.  
  64. /* Delete the indentation from the current line. */
  65.  
  66. void
  67. WIndDel()
  68.     {
  69.     CLineA();
  70.     BMarkToPoint(cwin->point);
  71.     WDelWhite();
  72.     BPointToMark(cwin->point);
  73.     uarg = 0;
  74.     }
  75.  
  76.  
  77. /* ------------------------------------------------------------ */
  78.  
  79. /* Indent the next line the same as the current line. */
  80.  
  81. void
  82. WIndNext()
  83.     {
  84.     int cnt;
  85.  
  86.     BInsChar(NL);
  87.     BMoveBy(-1);
  88.     CLineA();
  89.     MovePastF(IsWhite);
  90.     cnt = BGetCol();
  91.     SearchNLF();
  92.     BInsTabSpaces(cnt);
  93.     uarg = 0;
  94.     }
  95.  
  96.  
  97. /* ------------------------------------------------------------ */
  98.  
  99. /* Open a new line indented the same as the current line. */
  100.  
  101. void
  102. WIndThis()
  103.     {
  104.     int cnt;
  105.  
  106.     CLineA();
  107.     MovePastF(IsWhite);
  108.     cnt = BGetCol();
  109.     CLineA();
  110.     BInsTabSpaces(cnt);
  111.     BInsChar(NL);
  112.     BMoveBy(-1);
  113.     uarg = 0;
  114.     }
  115.  
  116.  
  117. /* ------------------------------------------------------------ */
  118.  
  119. /* Insert a newline. */
  120.  
  121. void
  122. WInsNL()
  123.     {
  124.     BInsChar(NL);
  125.     }
  126.  
  127.  
  128. /* ------------------------------------------------------------ */
  129.  
  130. /* Insert a newline after the current position. */
  131.  
  132. void
  133. WInsNLA()
  134.     {
  135.     BInsChar(NL);
  136.     BMoveBy(-1);
  137.     }
  138.  
  139.  
  140. /* ------------------------------------------------------------ */
  141.  
  142. /* Delete the surrounding grayspace and leave exactly one blank. */
  143.  
  144. void
  145. WJoinGray()
  146.     {
  147.     GoToNotGrayB();
  148.     BMarkToPoint(cwin->point);
  149.     GoToNotGrayF();
  150.     BRegDelete(cwin->point);
  151.     BInsChar(SP);
  152.     }
  153.  
  154.  
  155. /* ------------------------------------------------------------ */
  156.  
  157. /* Center the current line. */
  158.  
  159. void
  160. WLineCenter()
  161.     {
  162.     int cnt;
  163.     int tmp;
  164.  
  165.     cnt = cbuf->c.right_margin;
  166.     if ((cnt -= cbuf->c.left_margin) >= 1) {
  167.         CLineA();
  168.         WDelWhite();
  169.         CLineE();
  170.         tmp = BGetCol();
  171.         if (tmp && tmp <= cnt) {
  172.             CLineA();
  173.             BInsTabSpaces(cbuf->c.left_margin + (cnt - tmp) / 2);
  174.             }
  175.         }
  176.     CLineE();
  177.     if (uarg > 1) BMoveBy(1);
  178.     }
  179.  
  180.  
  181. /* ------------------------------------------------------------ */
  182.  
  183. /* Print the line count of the point and the buffer. */
  184.  
  185. void
  186. WPrintLine()
  187.     {
  188.     char buf[LINEBUFFSIZE];
  189.     int pointline = 1;
  190.     int bufline = 1;
  191.     int markline = 1;
  192.  
  193.     uarg = 0;
  194.     BMarkToPoint(cwin->point);
  195.     BMoveToStart();
  196.     while (!BIsEnd()) {
  197.         if (SearchNLF()) ++bufline;
  198.         if (!BIsAfterMark(cwin->point)) pointline = bufline;
  199.         if (!BIsAfterMark(mark)) markline = bufline;
  200.         }
  201.     BPointToMark(cwin->point);
  202.  
  203.     xsprintf(buf,
  204.         TMaxCol() < 60 ?
  205.             "Line %u  Total %u  Mark %u " :
  206.             "Current line %u   Total lines %u   Mark on line %u ",
  207.         pointline, bufline, markline);
  208.     DView(buf);
  209.     }
  210.  
  211.  
  212. /* ------------------------------------------------------------ */
  213.  
  214. /* Print the margin settings */
  215.  
  216. void
  217. WPrintMar()
  218.     {
  219.     char buf[LINEBUFFSIZE];
  220.  
  221.     uarg = 0;
  222.     if (isuarg) {
  223.         xsprintf(buf, "\013R %d,T %d,L %d%s%s\n",
  224.             cbuf->c.right_margin,
  225.             cbuf->c.tab_spacing,
  226.             cbuf->c.left_margin,
  227.             cbuf->c.fill == 'N' ? ",N" : "",
  228.             cbuf->c.fill == 'F' ? ",F" : "");
  229.         BMarkToPoint(cwin->point);
  230.         BMoveToStart();
  231.         BInsStr(buf);
  232.         BPointToMark(cwin->point);
  233.         DView("Ruler inserted");
  234.         }
  235.     else    {
  236.         xsprintf(buf,
  237.             TMaxCol() < 60 ?
  238.     "Left %d  Right %d  Tab %d  Fill %s%s%s" :
  239.     "Left margin %d   Right margin %d   Tab spacing %d   Fill %s%s%s",
  240.             cbuf->c.left_margin,
  241.             cbuf->c.right_margin,
  242.             cbuf->c.tab_spacing,
  243.             cbuf->c.fill == 'N' ? "none" : "",
  244.             cbuf->c.fill == 'F' ? "hard" : "",
  245.             cbuf->c.fill == 'W' ? "word wrap" : "");
  246.         DView(buf);
  247.         }
  248.     }
  249.  
  250.  
  251. /* ------------------------------------------------------------ */
  252.  
  253. /* Print the current position. */
  254.  
  255. void
  256. WPrintPos()
  257.     {
  258.     char buf[LINEBUFFSIZE];
  259.     long tmp;
  260.  
  261.     BMarkSwap(mark);
  262.     tmp = BGetLocation();
  263.     BMarkSwap(mark);
  264.     xsprintf(buf,
  265.         TMaxCol() < 60 ?
  266.             "Pt %l  Len %l  Col %d  Mark %l" :
  267.             "Point %l   Length %l   Column %d   Mark %l ",
  268.         BGetLocation(),
  269.         BGetLength(cbuf),
  270.         BGetCol(),
  271.         tmp);
  272.     DView(buf);
  273.     }
  274.  
  275.  
  276. /* ------------------------------------------------------------ */
  277.  
  278. /* Ask for the fill mode and set this buffer's fill mode. */
  279.  
  280. void
  281. WSetFill()
  282.     {
  283.     int chr;
  284.  
  285.     uarg = 0;
  286.     for (;;) {
  287.         DEcho("Fill mode: ");
  288.         chr = xtoupper(KGetChar());
  289.         switch (chr) {
  290.  
  291.         case KEYQUIT:
  292.         case KEYABORT:
  293.         case BEL:
  294.         case ESC:
  295.             DModeLine();
  296.             return;
  297.             /*break;*/
  298.             
  299.         case 'N':
  300.         case 'F':
  301.         case 'W':
  302.             cbuf->c.fill = chr;
  303.             DModeLine();
  304.             return;
  305.             /*break;*/
  306.  
  307.         default:
  308.             DView("N)No filling   F)hard fill   W)word wrap");
  309.             break;
  310.             }
  311.         }
  312.     }
  313.  
  314.  
  315. /* ------------------------------------------------------------ */
  316.  
  317. /* Set this buffer's left margin to the argument. */
  318.  
  319. void
  320. WSetLeft()
  321.     {
  322.     if (!isuarg) {
  323.         DError("An explicit argument must be supplied.");
  324.         }
  325.     else    {
  326.         cbuf->c.left_margin = uarg;
  327.         WFixup(&cbuf->c);
  328.         }
  329.     uarg = 0;
  330.     }
  331.  
  332.  
  333. /* ------------------------------------------------------------ */
  334.  
  335. /* Set this buffer's right margin to the argument. */
  336.  
  337. void
  338. WSetRight()
  339.     {
  340.     if (!isuarg) {
  341.         DError("An explicit argument must be supplied.");
  342.         }
  343.     else    {
  344.         cbuf->c.right_margin = uarg;
  345.         WFixup(&cbuf->c);
  346.         }
  347.     uarg = 0;
  348.     }
  349.  
  350.  
  351. /* ------------------------------------------------------------ */
  352.  
  353. /* Set this buffer's tab spacing to the argument. */
  354.  
  355. void
  356. WSetTabs()
  357.     {
  358.     if (!isuarg) {
  359.         DError("An explicit argument must be supplied.");
  360.         }
  361.     else    {
  362.         cbuf->c.tab_spacing = uarg;
  363.         WFixup(&cbuf->c);
  364.         DNewDisplay();
  365.         }
  366.     uarg = 0;
  367.     }
  368.  
  369.  
  370. /* end of WHITE.C -- Whitespace-Oriented Commands */
  371.